package com.itCar.base.api.tacticsPaymentDemo;

import com.itCar.base.config.result.ResultBody;
import com.itCar.base.tools.StringUtilsBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName TestStrategyController
 * @Description TODO 接收支付类型和支付金额
 * @Author liuzhiguo
 * @Date 2024/9/18 9:18
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/admin", produces = "application/json")
@Api(tags = "策略模式+依赖注入实现多种支付方式")
public class TestStrategyController {

    @Autowired
    private PayStrategyContext payStrategyContext;

    @PostMapping("/pay")
    @ApiOperation(value = "支付模式")
    public ResultBody get(@RequestParam("type") String type, @RequestParam("amount") String amount) {
        //通过数字获取对应的支付枚举对象
        PayTypeEnum payTypeEnum = PayTypeEnum.getPayTypeEnum(type);

        PayStrategyContext payStrategyContext = StringUtilsBean.getBean(PayStrategyContext.class);

        Pay pay = payStrategyContext.getPayType(payTypeEnum);
        return pay.pay(Integer.valueOf(amount));
    }

}
